﻿using System;
using System.Collections.Generic;
using LPTask.Interfaces.Views;

namespace LPTask.Test.PresenterViews
{
    internal class GeneralViewMock : IGeneralView
    {
        public event EventHandler ActiveTaskChangeNeeded;
        public event EventHandler SolveTaskNeeded;

        public string SelectedTaskName { get; private set; }
       
        public bool Enabled { get; set; }

        public IUserMessageView UserMessageView { get; private set; }

        public bool Active { get; private set; }
 
        private List<string> _taskNames;

        public GeneralViewMock()
        {
            _taskNames = new List<string>();
            Enabled = true;
        }

        public void ShowView()
        {
            Active = true;
        }

        public void SetTaskNames(List<string> taskNames)
        {
            _taskNames = new List<string>(taskNames);
        }

        public void SetActiveTaskView(ITaskView taskView)
        {
        }

        public void SelectName(int index)
        {
            if (index < _taskNames.Count)
            {
                SelectedTaskName = _taskNames[index];
                OnActiveTaskChangeNeeded();
            }
        }

        public void ActivateSolving()
        {
            OnSolveTaskNeeded();
        }

        private void OnActiveTaskChangeNeeded()
        {
            if (ActiveTaskChangeNeeded != null)
            {
                ActiveTaskChangeNeeded(this, EventArgs.Empty);
            }
        }

        private void OnSolveTaskNeeded()
        {
            if (SolveTaskNeeded != null)
            {
                SolveTaskNeeded(this, EventArgs.Empty);
            }
        }
    }
}